#pragma once
#include "Texture.h"
#include "Camera.h"
#include "Effect.h"
#include "Singleton.h"
#include "EffectManager.h"
#include "MovableObject.h"

VAMPIRE_NAMESPACE_BEGIN

class _VampireExport SkyBox : public MovableObject
{
public:
	struct SkyBoxVertex
	{
		SkyBoxVertex(){}
		SkyBoxVertex(Real x, Real y, Real z) : pos(x, y, z) {}
		Vector3 pos;
		static const DWORD FVF;
	};

	SkyBox() : MovableObject(L"Sky"), mpVertexBuffer(NULL), mpIndexBuffer(NULL), mpVertexData(NULL), mpIndexData(NULL), mVertexCount(24), mFaceCount(12) {}

	~SkyBox() 
	{
		if (mpVertexData)
		{
			SAFE_DELETE_ARRAY(mpVertexData);
		}
		SAFE_RELEASE(mpIndexBuffer);
		SAFE_RELEASE(mpVertexBuffer);
	}

	void                       createSkyBox();

	void                       draw();

private:
	Real                       mSkyBoxSize;
	LPDIRECT3DVERTEXBUFFER9    mpVertexBuffer;         
	LPDIRECT3DINDEXBUFFER9     mpIndexBuffer;         
	SkyBoxVertex*              mpVertexData;
	WORD*                      mpIndexData;
	UINT                       mVertexCount;
	UINT                       mFaceCount;
};

class _VampireExport Sky : public MemoryAlloc
{
public:
	SINGLETON(Sky)

	Sky(void) : mpCubeTex(NULL), mbEnabled(FALSE) 
	{
		mpBox = VAMPIRE_NEW SkyBox; 
		mpBox->createSkyBox();
		mpEffect = EffectManager::getSingletonPtr()->createEffect(L"sky.hlsl", "SkyShader");
	}

	void                       draw();

	void                       begin();

	void                       end();

	void                       setTexture(Texture* tex);

	BOOL                       mbEnabled;

private:
	Texture*                   mpCubeTex;
	SkyBox*                    mpBox;   
	Effect*                    mpEffect;
};

VAMPIRE_NAMESPACE_END